Parse --features in `cargo metadata` the same
authorAlex Crichton <alex@alexcrichton.com>
Fri, 7 Oct 2016 16:50:29 +0000 (09:50 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 20 Oct 2016 17:08:43 +0000 (10:08 -0700)
This accidentally didn't accept space-separated features passed through
`--features` as the logic for doing the splitting wasn't shared. Let's share it!

src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_output_metadata.rs
tests/metadata.rs

index 7b6cb1b71a94c3d6f65fb9102d40232b1ba4a9fd..5a9513f94ccb38a2842e4877be6cc0910a76085f 100644 (file)
@@ -100,11 +100,14 @@ pub fn compile<'a>(ws: &Workspace<'a>, options: &CompileOptions<'a>)
 
 pub fn resolve_dependencies<'a>(ws: &Workspace<'a>,
                                 source: Option<Box<Source + 'a>>,
-                                features: Vec<String>,
+                                features: &[String],
                                 all_features: bool,
                                 no_default_features: bool,
                                 spec: &'a [String])
                                 -> CargoResult<(PackageSet<'a>, Resolve)> {
+    let features = features.iter().flat_map(|s| {
+        s.split_whitespace()
+    }).map(|s| s.to_string()).collect::<Vec<String>>();
 
     let mut registry = try!(PackageRegistry::new(ws.config()));
 
@@ -161,9 +164,6 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
                          ref target_rustc_args } = *options;
 
     let target = target.map(|s| s.to_string());
-    let features = features.iter().flat_map(|s| {
-        s.split(' ')
-    }).map(|s| s.to_string()).collect::<Vec<String>>();
 
     if jobs == Some(0) {
         bail!("jobs must be at least 1")
index 131b93825db8c414eed214de6c79f4f70b20f60e..cda9b53e67f3ca8449bb01cd680d0bf45c616d06 100644 (file)
@@ -45,7 +45,7 @@ fn metadata_full(ws: &Workspace,
                  opt: &OutputMetadataOptions) -> CargoResult<ExportInfo> {
     let deps = try!(ops::resolve_dependencies(ws,
                                               None,
-                                              opt.features.clone(),
+                                              &opt.features,
                                               opt.all_features,
                                               opt.no_default_features,
                                               &[]));
index a180aae49a91cd3cd257bf6872b1cf687d17acc2..2ed82b294a0d3bbe63e8e9ec82b77069c4b892ef 100644 (file)
@@ -429,3 +429,23 @@ fn carg_metadata_bad_version() {
                 execs().with_status(101)
     .with_stderr("[ERROR] metadata version 2 not supported, only 1 is currently supported"));
 }
+
+#[test]
+fn multiple_features() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.1.0"
+            authors = []
+
+            [features]
+            a = []
+            b = []
+        "#)
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("metadata")
+                 .arg("--features").arg("a b"),
+                execs().with_status(0));
+}